#include "stdafx.h"
#include "Class7BezierDeg3.h"

#include "conio.h"

Class7BezierDeg3::Class7BezierDeg3()
{
	picID = NULL;

	resetBitMap();

	points[0][0] = 0;
	points[0][1] = 0;

	points[1][0] = 4;
	points[1][1] = 4;

	points[2][0] = 6;
	points[2][1] = 0;
}

Class7BezierDeg3::~Class7BezierDeg3()
{

}

double Class7BezierDeg3::computeDeg2(double t, char rooler = 'x')
{
	double param[3][3] = {
			{ -1, -2, 1},
			{-2, 2, 0},
			{1, 0, 0}
	};

	double ta[3] = { t * t, t, 1 };
	double p[3];
	double tmp[3];
	double retv = 0;
	int i;

	/* Get point rooler */
	switch (rooler) {
	case 'x':
	default:
		for (i = 0; i < 3; i++) {
			p[i] = points[i][0];
		}
		break;
	case 'y':
		for (i = 0; i < 3; i++) {
			p[i] = points[i][1];
		}
		break;
	}

	/* Compute value */
	for (i = 0; i < 3; i++) {
		int j;
		double tvalue = 0;

		for (j = 0; j < 3; j++) {
			tvalue += ta[j] * param[i][j];
		}

		tmp[i] = tvalue;
	}

	for (i = 0; i < 3; i++) {
		retv += tmp[i] * p[i];
	}

	cprintf("ret value is %f\n", retv);

	return retv;
}



void Class7BezierDeg3::drawPoint(CDC* pDC, int x, int y, COLORREF crColor)
{
	CRect rc(x, y, x, y);
	CBrush brush(RGB(255, 0, 0));

	pDC->FrameRect(rc, &brush);
}


void Class7BezierDeg3::drawPics(CDC* pDC)
{
	clearRect(pDC, 800, 800);


	double i;
#define PREC 1000

	for (i = 0; i <= PREC; i++) {
		int x = computeDeg2((1.0 / PREC) * i, 'x') * 100 + 20;
		int y = computeDeg2((1.0 / PREC) * i, 'y') * 100 + 20;

		drawPoint(pDC, x, y, RGB(255, 255, 0));
	}
}

